package com.djf.eg.exception;

import java.text.MessageFormat;

public class DRuntimeException extends RuntimeException {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4380649444603026548L;
	
	private String code;

    protected Object[] params;
    
    public DRuntimeException(String code, String message, Object... params) {
    	super(getMessageFormat(message, params));
        this.code = code;
        this.params = params;
    }
    
    
    public String getCode() {
        return code;
    }

   

    public Object[] getParams() {
        return params;
    }

    public void setParams(Object[] params) {
        this.params = params;
    }

    public void setCode(String code) {
        this.code = code;
    }
    
    
    public static String getMessageFormat(String message, Object... params){
        if(params==null || params.length==0){
            return message;
        }
        if (message == null) {
            return "";
        }
        return MessageFormat.format(message, params);
    }

}
